/*
* ============================================================================
*  Name        : sea_timer_server.h
*  Part of     : Finite state machine framework
*  Description : Timer class definition
*  Version     : %version: %
*  
*
* ============================================================================
*/
/**
 * @file sea_timer_server.h
 * @brief Timer server. Separate thread that keeps track of all timers in the system
 *
 * @ingroup StateMachineFramework
 */
#include "sea.h"
#include "sea_queue.h"

#if !defined( __sea_timer_server_h__ )
#define __sea_timer_server_h__

namespace sea
{
    class Timer;

    /** 
     * @class TimerServer
     * @brief 
     *   Timer server. Runs timer thread and manages all timers objects. \b INTERNAL \b API. 
     *
     * @ingroup StateMachineFramework
     */
    class TimerServer: public OsThread
    {
        friend class Timer;
        friend class Engine;

    private:
        TimerServer( );
        ~TimerServer( );

        void exec( );
        void terminate( );
        void start_timer( Timer* timer );
        void stop_timer( Timer* timer );
        void update( );
        void wakeup( ) { m_signal.wakeup( ); }
        bool sleep( int timeout ){ return m_signal.wait( timeout ); }

    private:
        OsMutex m_lock;
        OsSignal m_signal;
        OsTime m_os_time;
        Queue m_timers;
        bool m_alive;
    };
}

#endif // #if !defined( __sea_timer_h__ )
